<template>
  <div class="catalogLayout">
    <p class="catalogtitle">云音乐特色榜</p>
    <ul>
      <li
        v-for="item in RankingListObj.list.slice(0, 4)"
        :key="item.id"
        class="catalogItem"
        :class="item.id == $route.query.id && 'catalogItemTe'"
        @click="SwitchList(item.id)"
      >
        <img class="coverImg" :src="item.coverImgUrl" alt="" />
        <div>
          <p class="catalogName">{{ item.name }}</p>
          <p class="updateFrequency">{{ item.updateFrequency }}</p>
        </div>
      </li>
    </ul>
    <p class="catalogtitle">云音乐特色榜</p>
    <ul>
      <li
        v-for="item in RankingListObj.list.slice(4)"
        :key="item.id"
        class="catalogItem"
        :class="item.id == $route.query.id && 'catalogItemTe'"
        @click="SwitchList(item.id)"
      >
        <img class="coverImg" :src="item.coverImgUrl" alt="" />
        <div>
          <p class="catalogName">{{ item.name }}</p>
          <p class="updateFrequency">{{ item.updateFrequency }}</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { RankingList } from "@/api";
export default {
  data() {
    return {
      RankingListObj: {
        list: [],
      },
    };
  },
  created() {
    this.getRankingList();
  },
  methods: {
    getRankingList() {
      RankingList().then((res) => {
        this.RankingListObj = res;
        this.$router.push({
          name: "rankinglist",
          query: {
            id: this.$route.query.id || res.list[0].id,
            time: Date.parse(new Date()),
          },
        });
      });
    },
    SwitchList(id) {
      this.$router.push({
        name: "rankinglist",
        query: { id: id },
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.catalogLayout {
  border-top: 1px solid #f9f9f9;
  background: #f9f9f9;
  .catalogtitle {
    margin-top: 40px;
    padding: 0 10px 12px 15px;
    font-size: 16px;
    font-weight: 700;
    color: #000;
  }
  .catalogItem {
    display: flex;
    padding: 10px 0 10px 20px;
    cursor: pointer;
    .coverImg {
      width: 40px;
      height: 40px;
      margin-right: 10px;
    }
    .catalogName {
      color: #000;
      font-size: 12px;
      overflow: hidden;
      margin-top: 2px;
      margin-bottom: 6px;
    }
    .updateFrequency {
      font-size: 12px;
      color: #999;
    }
    &:hover {
      background: #e6e6e6;
    }
  }
  .catalogItemTe {
    background: #e6e6e6;
  }
}
</style>